package v1

import (
	"daily-blog/global"
	"daily-blog/model"
	"daily-blog/pkg"
	"daily-blog/service"
	"github.com/gin-gonic/gin"
)

func CreateComment(c *gin.Context) {
	var comment model.Comment
	err := c.ShouldBindJSON(&comment)
	if err != nil {
		pkg.FailWithMessage("参数错误", c)
		global.GVA_LOG.Error(err.Error())
		return
	}
	if ok := service.CreateComment(&comment); !ok {
		pkg.Fail(c)
		return
	}
	pkg.Ok(c)

}
func DeleteComment(c *gin.Context) {
	postId := c.Query("post_id")
	commentId := c.Query("comment_id")
	if postId == "" || commentId == "" {
		pkg.FailWithMessage("参数错误,存在空值", c)
		return
	}
	if ok := service.DeleteComment(postId, commentId); !ok {
		pkg.Fail(c)
		return
	}
	pkg.Ok(c)
}
func GetCommentList(c *gin.Context) {
	postId := c.Query("post_id")
	if postId == "" {
		pkg.FailWithMessage("参数错误, 文章为空值", c)
		return
	}
	comments, ok := service.GetCommentList(postId)
	if !ok {
		pkg.Fail(c)
		return
	}
	pkg.OkWithData(comments, c)
}
func GetAllPostCommentList(c *gin.Context) {
	commentList, ok := service.GetAllPostAllCommentList()
	if !ok {
		pkg.Fail(c)
		return
	}
	pkg.OkWithData(commentList, c)
}
